import * as XLSX from "xlsx";
import {
  ElMessage
} from "element-plus";
export function downloadExcel(tableData, type) {
  //   console.log(tableData, type);
  let data = [];
  let head = [];
  if (type == 1) {
    tableData.heads.forEach((element) => {
      if (!element.sensitivity) {
        head.push(element.label);
      }
    });
    data.push(head);
    tableData.value.forEach((element, index) => {
      let rawData = [];
      tableData.heads.forEach((child) => {
        if (!child.sensitivity) {
          rawData.push(element[child.prop]);
        }
      });
      data.push(rawData);
    });
  } else {
    tableData.heads.forEach((element) => {
      head.push(element.label);
    });
    data.push(head);
    tableData.value.forEach((element, index) => {
      let rawData = [];
      tableData.heads.forEach((child) => {
        rawData.push(element[child.prop]);
      });
      data.push(rawData);
    });
  }
  const ws = XLSX.utils.aoa_to_sheet(data);
  const wb = XLSX.utils.book_new();
  XLSX.utils.book_append_sheet(wb, ws, "Sheet1");
  XLSX.writeFile(wb, Date.now() + ".xlsx");
  ElMessage("成功导出Excel文件")
}
